package com.pd.backend.service.impl;

import com.pd.backend.entity.PdCacheLine;
import com.pd.backend.dao.PdCacheLineDao;
import com.pd.backend.service.PdCacheLineService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 缓冲路线表(PdCacheLine)表服务实现类
 *
 * @author GuoXinChao.126@gmail.com
 * @since 2023-02-27 17:14:32
 */
@Service("pdCacheLineService")
public class PdCacheLineServiceImpl implements PdCacheLineService {
    @Resource
    private PdCacheLineDao pdCacheLineDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PdCacheLine queryById(String id) {
        return this.pdCacheLineDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param pdCacheLine 筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<PdCacheLine> queryByPage(PdCacheLine pdCacheLine, PageRequest pageRequest) {
        long total = this.pdCacheLineDao.count(pdCacheLine);
        return new PageImpl<>(this.pdCacheLineDao.queryAllByLimit(pdCacheLine, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param pdCacheLine 实例对象
     * @return 实例对象
     */
    @Override
    public PdCacheLine insert(PdCacheLine pdCacheLine) {
        this.pdCacheLineDao.insert(pdCacheLine);
        return pdCacheLine;
    }

    /**
     * 修改数据
     *
     * @param pdCacheLine 实例对象
     * @return 实例对象
     */
    @Override
    public PdCacheLine update(PdCacheLine pdCacheLine) {
        this.pdCacheLineDao.update(pdCacheLine);
        return this.queryById(pdCacheLine.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.pdCacheLineDao.deleteById(id) > 0;
    }
}
